package com.zc.app.sys.service;

import com.github.pagehelper.PageHelper;
import com.zc.app.sys.dao.mapper.SystemMenuPeerMapper;
import com.zc.app.sys.dao.peer.SystemMenuPeer;
import com.zc.framework.common.bean.MyPageInfo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by zc on 2016/11/23.
 */
@Service
public class SystemMenuService {
    private static Logger logger = LogManager.getLogger(SystemMenuService.class);

    @Autowired
    private SystemMenuPeerMapper systemMenuPeerMapper;

    public int createMenu(SystemMenuPeer menuPeer) {
        return systemMenuPeerMapper.insert(menuPeer);
    }

    public int updateMenu(SystemMenuPeer menuPeer){
        return systemMenuPeerMapper.updateByPrimaryKey(menuPeer);
    }

    public SystemMenuPeer queyMenuById(Integer menuId){
        return systemMenuPeerMapper.selectByPrimaryKey(menuId);
    }

    public int deleteByPrimaryKey(Integer menuId){
        return systemMenuPeerMapper.deleteByPrimaryKey(menuId);
    }

    public List<SystemMenuPeer> getParentMenu(){
        return systemMenuPeerMapper.getParentMenu();
    }

    /**
     * 分页显示菜单
     * @param menuPeer
     * @param pageNum
     * @param pageSize
     * @return
     */
    public MyPageInfo<SystemMenuPeer> getMenus(SystemMenuPeer menuPeer, int pageNum, int pageSize){
        PageHelper.startPage(pageNum, pageSize);
        return new MyPageInfo<SystemMenuPeer>(systemMenuPeerMapper.getMenus(menuPeer));
    }


    public List<SystemMenuPeer> getAllMenu(){
        return systemMenuPeerMapper.getAllMenu();
    }

}
